package com.ats.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ats.model.User;
import com.ats.service.FunctionService_xh;
import com.ats.serviceimpl.FunctionServiceImpl_xh;

import net.sf.json.JSONArray;
/**
 * 不同角色加载不同功能
 * @author xh
 *
 */
public class FuncController_xh extends HttpServlet {
	FunctionService_xh fs = new FunctionServiceImpl_xh();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("utf8");
		HttpSession session =req.getSession();
		String fids=((User)session.getAttribute("user")).getFids();
		int pid = Integer.parseInt(req.getParameter("pid"));
		//不同角色加载不同功能
		JSONArray as =fs.getFuncs(pid, fids);
		PrintWriter  pw = resp.getWriter();
		pw.write(as.toString());
		pw.flush();
		pw.close();
		
		
		
	}

}
